package Comparator;

import geometric3D.YZRectangle;

import java.util.Comparator;

public class YZRectangleComparator implements Comparator<YZRectangle> {

	boolean isIncreasing;
	
	public YZRectangleComparator(boolean isIncreasing) {
		super();
		this.isIncreasing = isIncreasing;
	}

	@Override
	public int compare(YZRectangle o1, YZRectangle o2) {
		if(isIncreasing){
			if(!o1.isPositiveFace()&&o2.isPositiveFace()){
				return -1;
			}else if(o1.isPositiveFace()&& !o2.isPositiveFace()){
				return 1;
			}else if(o1.getPosition().getX()< o2.getPosition().getX()){
				return -1;
			}else if(o1.getPosition().getX()> o2.getPosition().getX()){
				return 1;
			}else if(o1.getPosition().getY()> o2.getPosition().getY()){
				return -1;
			}else if(o1.getPosition().getY()< o2.getPosition().getY()){
				return 1;
			}else if(o1.getPosition().getZ()> o2.getPosition().getZ()){
				return -1;
			}else if(o1.getPosition().getZ()< o2.getPosition().getZ()){
				return 1;
			}else if(o1.getYSize() > o2.getYSize()){
				return 1;
			}else if(o1.getYSize() < o2.getYSize()){
				return -1;
			}else if(o1.getZSize() < o2.getZSize()){
				return -1;
			}else if(o1.getZSize() > o2.getZSize()){
				return 1;
			}
			return 0;
		}else{
			if(!o1.isPositiveFace()&&o2.isPositiveFace()){
				return 1;
			}else if(o1.isPositiveFace()&& !o2.isPositiveFace()){
				return -1;
			}else if(o1.getPosition().getX()< o2.getPosition().getX()){
				return 1;
			}else if(o1.getPosition().getX()> o2.getPosition().getX()){
				return -1;
			}else if(o1.getPosition().getY()> o2.getPosition().getY()){
				return -1;
			}else if(o1.getPosition().getY()< o2.getPosition().getY()){
				return 1;
			}else if(o1.getPosition().getZ()> o2.getPosition().getZ()){
				return -1;
			}else if(o1.getPosition().getZ()< o2.getPosition().getZ()){
				return 1;
			}else if(o1.getYSize() > o2.getYSize()){
				return 1;
			}else if(o1.getYSize() < o2.getYSize()){
				return -1;
			}else if(o1.getZSize() < o2.getZSize()){
				return -1;
			}else if(o1.getZSize() > o2.getZSize()){
				return 1;
			}
			return 0;
		}
	}

}
